package com.itany.mall.vo;

import java.util.List;

/**
 * 分页对象
 * @author 赵云
 *
 */
public class PageInfo<T> {

	// 当前页码
	private int pageNo;

	// 每页显示条数
	private int pageSize;

	// 总数据条数
	private int totalCount;

	// 每页要显示的条数
	private List<T> list;

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	/**
	 * 获取分页数
	 */
	public int getPageCount() {
		if (totalCount == 0) {
			return 1;
		}
		int tmp = this.totalCount % this.pageSize;
		if (tmp == 0) {
			return this.totalCount / this.pageSize;
		}
		return this.totalCount / this.pageSize + 1;
	}

	/**
	 * 是否有上一页
	 * @return
	 */
	public boolean hasPreviousPage() {
		return this.pageNo > 1;
	}

	/**
	 * 是否有下一页
	 * @return
	 */
	public boolean hasNextPage() {
		return this.pageNo < this.getPageCount();
	}

	/**
	 * 获取首页页码
	 * @return
	 */
	public int getFirstPageNo() {
		return 1;
	}

	/**
	 * 获取最后一页页码
	 * @return
	 */
	public int getLastPageNo() {
		return this.getPageCount();
	}

	/**
	 * 获取上一页码
	 * @return
	 */
	public int getPreviousPageNo() {
		return this.hasPreviousPage() ? this.pageNo - 1 : 1;
	}

	/**
	 * 获取下一页页码
	 * @return
	 */
	public int getNextPageNo() {
		return this.hasNextPage() ? this.pageNo + 1 : this.getPageCount();
	}
}
